libxl: retry QMP PCI device_add
authorJason Andryuk <jandryuk@gmail.com>
Wed, 27 Apr 2022 07:14:30 +0000 (09:14 +0200)
committerJan Beulich <jbeulich@suse.com>
Wed, 27 Apr 2022 07:14:30 +0000 (09:14 +0200)
commit0f4fd6b6d805c89d19843c7ad70adc772a7d1203
tree23110fbfb72d282aff5d3d3357dfcc91c25cae9b
parent010bc50adaf58c78db4ad1329b0130d96e13f8e2
libxl: retry QMP PCI device_add

PCI device assignment to an HVM with stubdom is potentially racy.  First
the PCI device is assigned to the stubdom via the PV PCI protocol.  Then
QEMU is sent a QMP command to attach the PCI device to QEMU running
within the stubdom.  However, the sysfs entries within the stubdom may
not have appeared by the time QEMU receives the device_add command
resulting in errors like:

libxl_qmp.c:1838:qmp_ev_parse_error_messages:Domain 10:Could not open '/sys/bus/pci/devices/0000:00:1f.3/config': No such file or directory

This patch retries the device assignment up to 10 times with a 1 second
delay between.  That roughly matches the overall hotplug timeout for
pci_add_timeout.  pci_add_timeout's initialization is moved to
do_pci_add since retries call into pci_add_qmp_device_add again.

The qmp_ev_parse_error_messages error is still printed since it happens
at a lower level than the pci code controlling the retries.  With that,
the "Retrying PCI add %d" message is also printed at ERROR level to
clarify what is happening.

Signed-off-by: Jason Andryuk <jandryuk@gmail.com>
Reviewed-by: Anthony PERARD <anthony.perard@citrix.com>
tools/libs/light/libxl_pci.c